package com.lzh.boot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzh.boot.dao.CustomDao;
import com.lzh.boot.pojo.Customer;
import com.lzh.boot.pojo.QueryVo;
import com.lzh.boot.service.CustomerService;
import com.lzh.boot.util.Page;
//客户管理
@Service
public class CustomerServiceImpl implements CustomerService{

	@Autowired
	private CustomDao customeDao;
	@Override
	public Page<Customer> getCustomerList(QueryVo queryvo) {
		//计算分页起始记录，
		if(queryvo.getPage()!=null){
			queryvo.setStart((queryvo.getPage()-1)*queryvo.getSize());
		}
		List<Customer> list = customeDao.getCustomerList(queryvo);
		//创建一个Page对象
		Page<Customer> page =new Page<>();
		page.setRows(list);
		
		Integer count = customeDao.getCustomerListCount(queryvo);
		page.setTotal(count);
		page.setSize(queryvo.getSize());
		page.setPage(queryvo.getPage());
		return page;
	}
	@Override
	public Customer getCustomerById(Long id) {
		Customer customer = customeDao.getCustomerById(id);
		return customer;
	}
	@Override
	public void updateCustomer(Customer customer) {
		customeDao.updateCustomer(customer);	
		
	}
	@Override
	public void deleteCustomer(Long id) {
		customeDao.deleteCustomer(id);
	}
	
}
